﻿namespace jzgl.Controller
{
    using jzgl.Model;
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Windows.Forms;

    internal class SysUserDB
    {
        private SqlConnection conn = null;
        private ConnDB conndb = new ConnDB();
        private DataTable table = null;
        private SysUser user = new SysUser();

        public SysUserDB()
        {
            this.conn = this.conndb.GetConnString();
        }

        public int Add_SysUser(SysUser Suser)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = "insert into SysUser values('" + Suser._UserName + "','" + Suser._UserFullname + "','" + Suser._UserPassword + "','" + Suser._UserGroup + "','" + Suser._UserRemark + "')";
                    num = this.conndb.Execute_Sql(sql);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            finally
            {
            }
            return num;
        }

        public int Delete_SysUser(SysUser Suser)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = "delete from SysUser where userName='" + Suser._UserName + "'";
                    num = this.conndb.Execute_Sql(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return num;
        }

        public int Is_UserExist(SysUser Suser)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = "select * from SysUser where  UserName='" + Suser._UserName + "' and UserPassWord='" + Suser._UserPassword + "' ";
                    num = this.conndb.Record_Count(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return num;
        }

        public int Is_UserExistBY_Name(SysUser Suser)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = "select * from SysUser where  UserName='" + Suser._UserName + "'";
                    num = this.conndb.Record_Count(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return num;
        }

        public DataTable Show_SysUser()
        {
            try
            {
                try
                {
                    string sql = "select * from SysUser";
                    this.table = this.conndb.FillDataTable(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return this.table;
        }

        public DataTable Show_SysUser(string useId)
        {
            try
            {
                try
                {
                    string sql = "select * from SysUser where UserName='" + useId + "'";
                    this.table = this.conndb.FillDataTable(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return this.table;
        }

        public void Show_SysUser(ComboBox box)
        {
            try
            {
                try
                {
                    string sqlstr = "select * from SysUser";
                    this.conndb.comboxDataBind(box, sqlstr, "UserId", "UserName");
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
        }

        public void Show_SysUser(DataGridView dgv)
        {
            try
            {
                try
                {
                    string sqlstr = "select * from SysUser";
                    this.conndb.dgvDataBind(dgv, sqlstr);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
        }

        public void Show_SysUserName(ComboBox box)
        {
            try
            {
                try
                {
                    string sqlstr = "select * from SysUser";
                    this.conndb.comboxDataBind(box, sqlstr, "UserId", "UserFullName");
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
        }

        public DataTable Show_userIdBy_FullName(string userFullName)
        {
            try
            {
                try
                {
                    string sql = "select * from SysUser where UserFullname='" + userFullName + "'";
                    this.table = this.conndb.FillDataTable(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return this.table;
        }

        public int Update_SystemUser(SysUser Suser)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = "update SysUser set UserRemark='" + Suser._UserRemark + "',UserFullName='" + Suser._UserFullname + "',UserGroup='" + Suser._UserGroup + "'  where  UserName='" + Suser._UserName + "'";
                    num = this.conndb.Execute_Sql(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return num;
        }

        public int Update_SystemUser_Password(SysUser Suser)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = "update  SysUser set  UserPassWord='" + Suser._UserPassword + "' where UserName='" + Suser._UserName + "'";
                    num = this.conndb.Execute_Sql(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return num;
        }
    }
}

